

#include <ostream>
#include <map>

#include "position.h"

using namespace std;


Position::Position()
{
}


Position::Position(const Position &pos)
{
	m_mapPosition = pos.m_mapPosition;
}

Position& Position::operator=(const Position &pos)
{
	if(&pos == this)
		return *this;

	this->m_mapPosition = pos.m_mapPosition;
	return *this;
}

void Position::add(const int index)
{
	const int size = m_mapPosition.size();
	m_mapPosition[index] = size;
}

ostream& operator<<(ostream &os, const Position &pos)
{
	for(map<int,int>::const_iterator iter = pos.m_mapPosition.begin();
		iter != pos.m_mapPosition.end();
		++iter)
	{
		os <<"("<<iter->first<<","<<iter->second<<") ";
	}
	return os;
}

const int Position::pos(const int index) const
{
	map<int,int>::const_iterator iter = m_mapPosition.find(index);
	if(iter != m_mapPosition.end())
	{
		return iter->second;
	}
	return -1;
}
 
const int Position::size(void) const
{
	return m_mapPosition.size();
}



#ifdef  TEST_POSITION

#include <iostream>

int main(void)
{
	Position pos0;

	for(int i = 1; i < 10; i+=2)
		pos0.add(i);

	std::cout<<pos0<<std::endl;

	Position pos1 = pos0;
	std::cout<<pos1<<std::endl;

	Position pos2;
	pos2 = pos1;
	std::cout<<pos2<<std::endl;

	std::cout<<pos2.pos(0)<<std::endl;
	std::cout<<pos2.pos(1)<<std::endl;
	std::cout<<pos2.pos(2)<<std::endl;
	std::cout<<pos2.pos(3)<<std::endl;
	std::cout<<pos2.pos(4)<<std::endl;
	std::cout<<pos2.pos(5)<<std::endl;
	std::cout<<pos2.pos(6)<<std::endl;
	std::cout<<pos2.pos(7)<<std::endl;
	std::cout<<pos2.pos(8)<<std::endl;

	return 0;
}


/*
compile : g++ -g -o test_position -DTEST_POSITION position.cpp
*/
#endif
